

$(function () {
    var currentPage = 1;
    var pageSize = 5;

    render();
    function render() {
        $.ajax({
            url: '/category/queryTopCategoryPaging',
            type: 'GET',
            data: {
                page: currentPage,
                pageSize: pageSize,
            },
            dataType: 'json',
            success: function (info) {
                console.log(info);
                var strhtml = template('tmp', info);
                $('tbody').html(strhtml);
                
                $("#pagintor").bootstrapPaginator({
                    bootstrapMajorVersion: 3,//默认是2，如果是bootstrap3版本，这个参数必填
                    currentPage: currentPage,//当前页
                    totalPages: Math.ceil(info.total / info.size),//总页数
                    onPageClicked: function (_, _, _, page) {
                        //为按钮绑定点击事件 page:当前点击的按钮值
                        currentPage = page;
                        render();
                    }

                });
            }
        })
    }



    //5.表单验证
    $('#form').bootstrapValidator({
        //1. 指定不校验的类型，默认为[':disabled', ':hidden', ':not(:visible)'],可以不设置
        excluded: [],

        //2. 指定校验时的图标显示，默认是bootstrap风格
        feedbackIcons: {
            valid: 'glyphicon glyphicon-ok',
            invalid: 'glyphicon glyphicon-remove',
            validating: 'glyphicon glyphicon-refresh'
        },

        fields: {
            brandName: {
                validators: {
                    notEmpty: {
                        message: '不能为空',
                    }
                }
            },
        }
    })


    $('#form').on('success.form.bv', function (e) {
        e.preventDefault();
        console.log($('#form').serialize());
        
        $.ajax({
            url: '/category/addTopCategory',
            type: 'POST',
            data: $('#form').serialize(),
            dataType: 'json',
            success: function (info) {
                console.log(info);
                render();
                $('#addModal').modal('hide');

            }
        })
    })




})